package net.homelinux.chaoswg.io.renga.krypto.converter;

import java.math.BigInteger;

import net.homelinux.chaoswg.io.higherorderfunctions.AbstractUnaryFunction;
import net.homelinux.chaoswg.io.renga.core.converter.Converter;
import net.homelinux.chaoswg.io.renga.krypto.datatypes.numerical.UnsignedNBit;
import net.homelinux.chaoswg.io.renga.krypto.datatypes.vectors.BitVector;

public class UNBtoBVConverter extends AbstractUnaryFunction<BitVector, UnsignedNBit> implements Converter<BitVector, UnsignedNBit> {
    public final BitVector apply (final UnsignedNBit unb) {
        final int length = unb.getN();
        
        final BitVector bv = new BitVector (length);
        final BigInteger unbVal = unb.getValue();

        for (int i = 0; i < length; ++i) {
            bv.set(i, unbVal.testBit(( (length - 1) - i)));
        }

        return bv;
    }
}
